<?php
abstract class DomArMapper {
	
	protected $parentMapper;
	
	protected $properties = array();
		
	protected $listeners = array();
	
	protected $validators = array();
	
	abstract public function __construct();
	
	public static function getInstance() {
		
	}
	
	final public function getProperties() {
		return $this->properties;
	}
	
	final public function getProperty( $name ) {
		if( array_key_exists($name, $this->properties) ) {
			return $this->properties[$name];
		} else {
			return $this->parentMapper->getProperty($name);
		}
	}
	
	abstract public function prepareProperties();
	
	
	public function addListener( DomArListener $listener ) {
		$this->listeners[$propertyName][$event][] = $listener;
	}
	
	public function addValidator( DomArValidator $validator ) {
		$this->validators[$propertyName][] = $validator;
	}
	
	
	
	
	
	
	public function insert( DomArDomainObject $object ) {
		$object->setStatus( DomArDomainObject::STATUS_CLEAN );
		
		$set = new DomArInsertValueSet();
		foreach( $object->getProperties() as $property ) {
			$property->insert( $this->object, $set );
		}
		
		$query = 'INSERT INTO __table__ ('.$set->getColumns().') VALUES ('.$set->getValues().')';

		$this->object->setId( DomArIdGenerator::acquireFor( $this->object ) );
	}
	
	public function update( DomArDomainObject $object ) {
		$object->setStatus( DomArDomainObject::STATUS_CLEAN );
		
		$set = new DomArUpdateValueSet();
		foreach( $object->getDirtyProperties() as $property ) {
			$property->update( $this->object, $set );
		}
		
		$query = 'UPDATE __table__ SET '.$set->getUpdates().' WHERE id = '.$object->getId().'';

	}
	
	public function delete( DomArDomainObject $object ) {
		$object->setStatus( DomArDomainObject::STATUS_NULL );
		DomArIdentityMap::remove( $object );
		$object->setId( 0 );
	}
	
}
?>